# MindPlus
# maixduino
from ASR import asr
import sensor
import image
import time
import lcd
import os  #导入系统库


def camera_init():
  sensor.reset()
  sensor.set_pixformat(sensor.RGB565)
  sensor.set_framesize(sensor.QVGA)
  sensor.skip_frames(10)
  sensor.run(1)


camera_init()
volume=os.listdir("/sd/xiangce")  #读取相册文件夹下的所有文件名
print(volume)
lcd.init(freq=15000000, color=0, invert=0)
model = asr.newModel()
YuLiao = ["拍照", "茄子","相册"]
print("开始训练")
for ZhiLing in YuLiao:
  asr.training(ZhiLing, model)
print("训练完成")
asr.run(model)
while True:
  frame = sensor.snapshot()
  result = asr.recognize()
  lcd.display(frame)
  if ((result == (str("拍照"))) or (result == (str("茄子")))):
    print(result)
    frame = frame.lens_corr(1,1)
    lcd.display(frame)
    frame.save((str("/sd/xiangce/") + str((str(time.time()) + str(".jpg")))))
    time.sleep(3)
  if (result == (str("相册"))):
    lcd.display(image.Image((str("/sd/xiangce/") + str((str("44") + str(".jpg"))))))
    time.sleep(5)
